package zjh_20230328;

import zjh_20230327.OldPerson;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class Demo01 {
    public static void main(String[] args) {
        OldPerson oldPerson = new OldPerson();
        Class<OldPerson> oldPersonClass = OldPerson.class;

        try {
            Constructor<OldPerson> constructor = oldPersonClass.getConstructor();
            OldPerson oldPerson1 = constructor.newInstance();
            Field house = oldPersonClass.getDeclaredField("house");
            house.setAccessible(true);
            house.set(oldPerson1, 2);
            house.get(oldPerson1);
//            System.out.println(Arrays.toString());
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        }

    }
}
